package jsen.tool.ddd.demo.domain.parking;

import jsen.tool.ddd.adapter.infrastructure.specification.ISpecification;
import jsen.tool.ddd.demo.domain.base.DomainObject;
import jsen.tool.ddd.demo.domain.parking.spec.parking.ParkingLotStatusSpec;
import jsen.tool.ddd.domain.ValueObject;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

/**
 * 空闲、可用、废弃
 *
 * @author jsen
 * @date 2021/10/6
 */
@ValueObject(name = "ParkingStatus", desc = "当前车位统计")
@Getter
@Builder
@ToString
public class ParkingLotStatus implements DomainObject {
    private final ISpecification<ParkingLotStatus> strict = new ParkingLotStatusSpec();
    private final int carCnt;
    private final int freeLocationCnt;
    private final int busyLocationCnt;

    public ParkingLotStatus parkingCntChange(int free, int busy) {
        return ParkingLotStatus.builder().carCnt(carCnt).freeLocationCnt(free).busyLocationCnt(busy).build();
    }

    public ParkingLotStatus carCntChange(int carCnt) {
        return ParkingLotStatus.builder().carCnt(carCnt).freeLocationCnt(freeLocationCnt)
                .busyLocationCnt(busyLocationCnt).build();
    }

    public boolean isFull() {
        return carCnt >= freeLocationCnt + busyLocationCnt;
    }
}
